﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec.NTD
{
    public partial class Defualt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["NTD"] == null)
            {
                Response.Redirect("/nha-tuyen-dung.html");
                return;
            }
            if(!IsPostBack)
            {
                LoadData();
            }
        }
        public void LoadData()
        {
            DAL.UserTuyenDung user = BLL.TuyenDung.UserHelper.Get_UserEmail(Session["NTD"].ToString());
            rptlistCV.DataSource = BLL.TuyenDung.DangTuyenHelper.List_TinTuyenDungTrangTaiKhoan(user.UserId, 5);
            rptlistCV.DataBind();
        }
        protected void rptlistCV_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                int tuyenDungId = int.Parse(e.CommandArgument.ToString());
                DAL.tbl_TD_TuyenDung tuyenDung = BLL.TuyenDung.DangTuyenHelper.Get_TinTuyenDung(tuyenDungId);
                Response.Redirect("/nha-tuyen-dung/" + tuyenDungId + "dang-tuyen-dung-buoc" + (tuyenDung.Step + 1) + ".html");
            }
        }
        protected void btDangViecLam_Click(object sender, EventArgs e)
        {
            Response.Redirect("/nha-tuyen-dung/dang-tuyen-dung.html");
        }

        protected void btActive_Click(object sender, EventArgs e)
        {
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            foreach (RepeaterItem item in rptlistCV.Items)
            {
                HiddenField hiTuyenDungId = item.FindControl("hiTuyenDungId") as HiddenField;
                CheckBox checkList = item.FindControl("checkList") as CheckBox;
                if (checkList.Checked == true)
                {
                    BLL.TuyenDung.DangTuyenHelper.Update_TinhTrang(int.Parse(hiTuyenDungId.Value), 2);
                }
            }
            Response.Redirect(path);
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            foreach (RepeaterItem item in rptlistCV.Items)
            {
                HiddenField hiTuyenDungId = item.FindControl("hiTuyenDungId") as HiddenField;
                CheckBox checkList = item.FindControl("checkList") as CheckBox;
                if (checkList.Checked == true)
                {
                    BLL.TuyenDung.DangTuyenHelper.Delete_TinTuyenDung(int.Parse(hiTuyenDungId.Value));
                }
            }
            Response.Redirect(path);
        }
    }
}